#@layout()
#define script()
<script>

    $('.del-action').on('click', function () {
        var id = $(this).attr("data-id");
        if (id == 1){
            alert("总部不能被删除！");
            return;
        }

        if (confirm('确定要删除该分类吗？删除后不可恢复')) {
            ajaxGet("#(CPATH)/admin/department/doDel/" + id);
        }
    });

    $(".tflag").each(function () {
        $(this).on('click', function () {
            $("#flag").val($(this).text());
        })
    });


</script>
#end
#define content()
    <section class="content-header">
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-6">

                    <div class="row mb-2">
                        <div class="col-sm-12">
                            <h1>
                                机构部门
                                <small data-toggle="tooltip" title="" data-placement="right"
                                       data-trigger="hover"><i class="nav-icon far fa-question-circle"></i></small>
                                <small> 首页 / 用户 / 机构部门 </small>
                            </h1>
                        </div>
                    </div>
                </div>
            </div>

        </div><!-- /.container-fluid -->
    </section>

    <section class="content">

        <div class="row">
            <div class="col-lg-5">
                <div class="card card-outline card-primary">
                    <!-- form start -->
                    <form class=" form-setting autoAjaxSubmit" autocomplete="off"
                          action="#(CPATH)/admin/department/doSave"
                          data-ok-href="#(CPATH)/admin/department/list"
                          data-ok-message="数据保存成功"
                          method="post">
                        <input type="hidden" name="department.id" value="#(department.id ??)">
                        <input type="hidden" name="department.type" value="1">
                        <div class="card-body">
                            <div class="form-group row">
                                <label class="col-sm-2 col-form-label"><span class="text-danger mr-2">*</span> 名称 </label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" placeholder="取个适合的部门机构名称..." required
                                           value="#(department.name ??)" name="department.name">
                                </div>
                            </div>

                            #if(!(department && department.id == 1))
                            <div class="form-group row">
                                <label class="col-sm-2 col-form-label"><span class="text-danger mr-2">*</span> 父级</label>
                                <div class="col-sm-9">
                                    <select class="form-control" name="department.pid">
                                        #for(c : departments)
                                        #if(department && department.pid == c.id)
                                        <option value="#(c.id)" selected>#(c.layerString) #(c.name)</option>
                                        #elseif(department && (department.id == c.id || department.isMyChild(c.id)))
                                        <option value="#(c.id)" disabled>#(c.layerString) #(c.name)</option>
                                        #else
                                        <option value="#(c.id)">#(c.layerString) #(c.name)</option>
                                        #end
                                        #end
                                    </select>
                                </div>
                            </div>
                            #end


                            <div class="form-group row">
                                <label class="col-sm-2 col-form-label">编号</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" placeholder="部门编号"
                                           value="#(department.code ??)" name="department.code">
                                </div>
                            </div>


                            #if(!(department && department.id == 1))
                            <div class="form-group row">
                                <label class="col-sm-2 col-form-label">排序</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" placeholder="排序的序号"
                                           value="#(department.order_number ??)"
                                           name="department.order_number">
                                    <p class="text-muted"> 越小的数字越靠前，只在同级上影响。 </p>
                                </div>
                            </div>
                            #end



                            <div class="form-group row">
                                <label class="col-sm-2 col-form-label">备注</label>
                                <div class="col-sm-9">
                                    <textarea rows="3" class="form-control"
                                              placeholder="..."
                                              name="department.description">#(department.description ??)</textarea>
                                </div>
                            </div>


                        </div>

                        <!-- /.card-body -->
                        <div class="card-footer">
                            <div class="offset-sm-2 col-sm-10 submit-block">
                                <div class="card-submit">
                                    <button type="submit" class="btn btn-primary">提交</button>
                                </div>
                            </div>
                        </div>
                        <!-- /.card-footer -->
                    </form>
                </div>
            </div>
            <div class="col-lg-7">
                <div class="card card-outline card-primary">

                    <div class="card-body p-0  ">

                        <table class="table table-striped">
                            <tbody>
                            <tr>
                                <th style="width: 40%">名称</th>
                                <th>编号</th>
                                <th>备注</th>
                                <th>排序</th>
                            </tr>
                            #for(department : departments)
                            <tr>
                                <td>
                                    <strong>
                                            #(department.layerString) #(department.name ??)
                                    </strong>
                                    <div class="jp-action-card">
                                        <div class="jp-action-body">
                                            <a href="#(CPATH)/admin/department/list/#(department.id)">编辑</a>
                                            #if(department.id != 1)
                                            |  <a href="javascript:;" class="del-action red-action" data-id="#(department.id)">删除</a>
                                            #end
                                        </div>
                                    </div>
                                </td>
                                <td>#(department.code ??)</td>
                                <td>#(department.description ??)</td>
                                <td>#(department.order_number ??)</td>
                            </tr>
                            #else
                            <tr class="nodata"><td colspan="999">暂无数据</td> </tr>
                            #end
                            </tbody>
                        </table>
                    </div>
                    <!-- /.card-body -->
                    <div class="card-footer">
                        <div class="row">
                            <div class="col-sm-12">
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.card -->
            </div>
            </div>
    </section>


#end
